package com.hx.controller;

import com.hx.poji.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class UserController {

    @GetMapping("/user")
    public List<User> select(){
        List<User> users = new ArrayList<>();
        users.add(new User(12,"tom","男","454"));
        users.add(new User(13,"jack","男","5465"));

        return users;
    }

    @PutMapping("/user")
    public User update(@RequestBody User user){
        log.info("{}",user);
        user.setName("zhangsan");
        user.setGender("男");
        return user;
    }


    @PostMapping("/user")
    public User save(@RequestBody User user){
        log.info("{}",user);
        user.setId(123);
        return user;
    }

    @DeleteMapping("/user/{id}")
    public String delete(@PathVariable(name = "id")Integer id){
        log.info("{}",id);
        return "user delete success";
    }
}
